var sleep = require("../Util/sleep");
var events = require("events");
var eventEmitter = new events.EventEmitter();

eventEmitter.on("e1", foo1);
eventEmitter.on("e2", foo2);

eventEmitter.emit("e1");
eventEmitter.emit("e2");
console.log("process end.");

function foo1(){
    setImmediate(function(){
        console.log("foo1 start.");
        sleep(5000);
        console.log("foo2 start.");
    });
}

function foo2(){
    console.log("foo2 func.");
}